/*
	callback{
		broadcast:{number,type,msg:{number,msg}},
		gossip:{number,msg:{number,msg}},
		loadIn:{res},
		loginIn{res}
	}
*/
var callback=function(){
	var user;
	function init(u){
		user=u;
	}
	function regist(u){
		$('#registReturn').html(u);
	}
	function loadIn(res){}
	function loginIn(res){
		//$('#dianliao .control .user-name').html(res.user.nick);
		//好友信息处理
		for(var i in res.friend){
			if(res.friend[i].listType=='0'){
				user.addFriend(res.friend[i]);
				if(res.friend[i].status==1){
					$('#dl-friend').prepend('<div class="friend fOnline f-'+res.friend[i].number+'" number="'+res.friend[i].number+'" onclick="friendClick(this);"><img src="'+res.friend[i].avatar+'" class="avatar"><div class="nick"><a>'+res.friend[i].nick+'</a></div></div>');
				}else{
					$('#dl-friend').append('<div class="friend f-'+res.friend[i].number+'" number="'+res.friend[i].number+'" onclick="friendClick(this);"><img src="'+res.friend[i].avatar+'" class="avatar"><div class="nick"><a>'+res.friend[i].nick+'</a></div></div>');
				}
			}else if(res.friend[i].listType=='1'){
				if(res.friend[i].status==1){
					$('#dl-recently').prepend('<div class="friend fOnline f-'+res.friend[i].number+'" number="'+res.friend[i].number+'" onclick="friendClick(this);"><img src="'+res.friend[i].avatar+'" class="avatar"><div class="nick"><a>'+res.friend[i].nick+'</a></div></div>');
				}else{
					$('#dl-recently').append('<div class="friend f-'+res.friend[i].number+'" number="'+res.friend[i].number+'" onclick="friendClick(this);"><img src="'+res.friend[i].avatar+'" class="avatar"><div class="nick"><a>'+res.friend[i].nick+'</a></div></div>');
				}
			}
		}
		recentlyOnMouseOver();
		//自己信息处理
		user.setMsg('avatar',res.user.avatar);
		user.setMsg('level',res.user.level);
		user.setMsg('nick',res.user.nick);
	}
	function gossip(msg){
		var friend=$('.f-'+msg.number);
		var u={};
		u.avatar=friend.find('.avatar').attr('src');
		u.nick=friend.find('.nick a').html();
		var date = new Date();
		var time=date.getFullYear()+'-';
		time+=(date.getMonth()+1)+'-';
		time+=date.getDate()+' ';
		time+=date.getHours()+':';
		time+=date.getMinutes();
		var html='<div class="msgl"><div class="avatar"><img src="'+u.avatar+'">'+u.nick+'</div><div class="chat-content"><div class="text"><p>'+msg.msg+'</p><span>'+time+'</span></div></div></div>';
		if(!($('.msg-'+msg.number).length>0)){
			$('#dl-tall-win .dl-msg').append('<div class="msg msg-'+msg.number+'" style="display:none;"></div>');
		}
		//当前不在和其对话状态
		if($('.msg-'+msg.number).css('display')=='none'){
			if(friend.find('.tip').length>0){
				friend.find('.tip').html(friend.find('.tip').html()-(-1));
			}else{
				friend.append('<div class="tip">1</div>')
			}
			if($('#dl-tip').html()==''){
				$('#dl-tip').html('1');
			}else{
				$('#dl-tip').html($('#dl-tip').html()-(-1));
			}
		}
		$('.msg-'+msg.number).append('<div class="msgl">'+html+'</div>');
	}
	function broadcast(number,type,msg){

	}
	function returns(type,data){
		switch(type){
			case 'gossip':
				if(data=='false'){
					alert('发送失败！');
				}else{
					var u=user.getUser();
					var date = new Date();
					var time=date.getFullYear()+'-';
					time+=(date.getMonth()+1)+'-';
					time+=date.getDate()+' ';
					time+=date.getHours()+':';
					time+=date.getMinutes();
					$('#dl-tall-win .dl-msg .msg-'+data).append('<div class="msgr"><div class="avatar"><img src="'+u.avatar+'">'+u.nick+'</div><div class="chat-content"><div class="text"><p>'+$('#msg-post').html()+'</p><span>'+time+'</span></div></div></div>');
					$('#msg-post').html('');
				}
			break;
			case 'broadcast':
			break;
			case 'addFriend':
				if(data.code==0){
					if(data.listType=='0'){
						$('.menu-content .tip-content').html('('+data.msg+')');
						setTimeout("$('.menu-content .tip-content').html('');", 3000);
					}else if(data.listType=='1'){
					}
				}else if(data.code==1){
					if(data.listType=='0'){
						$('.menu-content .tip-content').html('(添加成功)');
						setTimeout("$('.menu-content .tip-content').html('');", 3000);
						if(data.data.status==1){
							$('#dl-friend').prepend('<div class="friend fOnline f-'+data.data.number+'" number="'+data.data.number+'" onclick="friendClick(this);"><img src="'+data.data.avatar+'" class="avatar"><div class="nick"><a>'+data.data.nick+'</a></div></div>');
						}else{
							$('#dl-friend').append('<div class="friend f-'+data.data.number+'" number="'+data.data.number+'" onclick="friendClick(this);"><img src="'+data.data.avatar+'" class="avatar"><div class="nick"><a>'+data.data.nick+'</a></div></div>');
						}
					}else if(data.listType=='1'){
					}
				}
			break;
			case 'delFriend':
				if(data.code==0){
					if(data.listType=='0'){
						$('.menu-content .tip-content').html('('+data.msg+')');
						setTimeout("$('.menu-content .tip-content').html('');", 3000);
					}else if(data.listType=='1'){
						alert(data.msg);
					}
				}else if(data.code==1){
					if(data.listType=='0'){
						$('.menu-content .tip-content').html('(删除成功)');
						setTimeout("$('.menu-content .tip-content').html('');", 3000);
						$('#tall-menu .f-'+data.data.number+' i').click();
						$('.f-'+data.data.number).remove();
					}else if(data.listType=='1'){
						$('#dl-recently .f-'+data.data.number).remove();
					}
				}
			break;
			default:console.log('此回调未处理。。。。。');
			break;
		}
	}
	function err(type,data){console.log('err--'+type+':::'+data);}
	return {
		'loadIn':loadIn,
		'loginIn':loginIn,
		'gossip':gossip,
		'broadcast':broadcast,
		'returns':returns,
		'err':err,
		'regist':regist,
		'init':init
	};
}